package swa2012.telco.provider;

import java.util.Collection;
import java.util.Collections;
import java.util.HashSet;
import java.util.Map;
import java.util.Set;
import java.util.concurrent.ConcurrentHashMap;

import swa2012.telco.broker.beans.*;
/**
 * @author kumar aberer
 * @date 10.06.2012
 */
public class MessageStorage {
	
	private final Map<String, Set<Message>> msgs = new ConcurrentHashMap();

	public boolean addMessage(Message msg){
		if (!msgs.containsKey(msg.getReceiver().getID()))
			msgs.put(msg.getReceiver().getID(), new HashSet<Message>());
		
	return msgs.get(msg.getReceiver().getID()).add(msg);
	}
	
	public Collection<Message> getMessages(String clientID){
		if(msgs.containsKey(clientID))
		{
			msgs.remove(clientID);
			return msgs.get(clientID);
		}
		
		return Collections.emptyList();
	}
	
}
